﻿@namespace AntDesign
@inherits AntInputComponentBase<string>
@typeparam TOption
@using AntDesign.Internal

<CascadingValue Value='$"ant-select-dropdown"' Name="PrefixCls">
    <OverlayTrigger @ref="_overlayTrigger"
                    Style="display: inline"
                    IsButton="@true"
                    Disabled="false"
                    Trigger="[]"
                    BoundaryAdjustMode="@BoundaryAdjustMode"
                    PopupContainerSelector="@PopupContainerSelector"
                    OverlayEnterCls="ant-slide-up-enter ant-slide-up-enter-active ant-slide-up"
                    OverlayLeaveCls="ant-slide-up-leave ant-slide-up-leave-active ant-slide-up"
                    OverlayClassName="@OverlayClassName"
                    OverlayStyle="@OverlayStyle"
                    OnVisibleChange="@OnOverlayTriggerVisibleChange">
        <Overlay>
            <CascadingValue Value="this" IsFixed="@true">
                <div style="max-height: 256px; overflow-y: auto; overflow-anchor: none; @_minWidth">
                    <div style="display: flex;flex-direction: column;">
                        @if (OverlayTemplate != null)
                        {
                            @OverlayTemplate
                        }
                        else if (_filteredOptions?.Any()==true)
                        {
                            @foreach (var option in _filteredOptions)
                            {
                                @if (OptionTemplate != null)
                                {
                                    @OptionTemplate(option)
                                }
                                else
                                {
                                    var label = OptionFormat == null ? option.Label : OptionFormat(option);
                                    <AutoCompleteOption Value="@option.Value" Label="@option.Label" Disabled="option.IsDisabled">
                                        @label
                                    </AutoCompleteOption>
                                }
                            }
                        }
                    </div>
                </div>
            </CascadingValue>
        </Overlay>
        <Unbound>
            <CascadingValue Value="this" IsFixed="@true">
                <CascadingValue Value="context" Name="OverlayTriggerContext" IsFixed>
                    @if (ChildContent == null)
                    {
                        <AutoCompleteInput @bind-Value="@CurrentValue" Placeholder="@Placeholder" Disabled="@Disabled" Style="@Style" Id="@Id" DebounceMilliseconds="DebounceMilliseconds" BindOnInput Class="@Class" />
                    }
                    else
                    {
                        @ChildContent
                    }
                </CascadingValue>
            </CascadingValue>
        </Unbound>
    </OverlayTrigger>
</CascadingValue>